package com.xyy.dfapi.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.*;

/**
 * @Auther: jone
 * @Date: 2025/11/21 - 11 - 21 - 10:29
 * @Description: com.xyy.dfapi.enums
 * @version: 1.0
 */
@Getter
@AllArgsConstructor
public enum CustomerTypeEnum {
    TYPE1("零售、终端", 1, 3, 10, 14, 15, 21, 22), TYPE4("生产企业", 16, 17), TYPE5("批发企业", 5, 6, 7, 8, 23), TYPE7("诊所", 4, 9), TYPE8("其他类型", 19, 20);

    private final String description;
    private final Set<Integer> typeCodes;

    // 类型码到枚举的映射
    private static final Map<Integer, CustomerTypeEnum> TYPE_CODE_MAP = new HashMap<>();

    static {
        // 初始化映射表
        for (CustomerTypeEnum type : CustomerTypeEnum.values()) {
            for (Integer code : type.typeCodes) {
                TYPE_CODE_MAP.put(code, type);
            }
        }
    }

    CustomerTypeEnum(String description, Integer... typeCodes) {
        this.description = description;
        this.typeCodes = new HashSet<>();
        this.typeCodes.addAll(Arrays.asList(typeCodes));
    }

    // 根据类型码获取枚举实例
    public static CustomerTypeEnum fromTypeCode(int typeCode) {
        return TYPE_CODE_MAP.getOrDefault(typeCode, TYPE1); // 默认返回零售
    }

}
